package cn.tedu.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ServletDemo06")
public class ServletDemo06 extends HttpServlet {
    //处理post方式提交的数据 请求参数中有中文，一定乱码！！！
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //验证，请求方式是post吗？
        String method = request.getMethod();
        //指定请求的方式使用的编码---解决中文乱码
        request.setCharacterEncoding("UTF-8");
        String n = request.getParameter("user");
        String p = request.getParameter("pwd");
        System.out.println("doPost---"+n+p+"----"+method);
    }

    //处理get方式提交的数据
    //处理get方式提交的数据：不会出现中文乱码，tomcat7.0以上都可以处理
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //method=get
        String method = request.getMethod();
        String n = request.getParameter("user");
        String p = request.getParameter("pwd");
        System.out.println(n+p+"====="+method);
    }
}
